<?php     
    $reg = Registry::getInstance();     
?>
<script type="text/javascript" src="/assets/js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="/assets/js/editor_init.js"></script>
<h2>Редактор</h2>
<?php echo $error;?>
<?php print form_open_multipart('admin/table/'.$action.'/'.$table); ?>
    <table width="100%" border="1" cellpadding = 5>
        <?php            
            foreach($fields_config as $index => $item) {                
                print '<tr><td width="20%">'.$item['caption'].'</td><td>';
                    $init['value'] = $field[$index];
                    $init['name'] = $index;
                    switch($item['type']) {                                        
                        case 'text':                            
                            print form_input($init);
                        break;
                        
                        case 'number':              
                            $init['size'] = 20;                                          
                            print form_input($init);
                        break;
                        
                        case 'select_dir':                              
                            if(!isset($reg[$item['rtable'].'_sql'])) {
                                $res = $this->db->select('id, '.$item['rfield'])->get($item['rtable']);
                                $reg[$item['rtable'].'_sql'] = $res;
                            } else {
                                $res = $reg[$item['rtable'].'_sql'];
                            }
                            
                            //print nl2br(print_r($loaded_data, true));
                            $sub = $res->result_array();
                            foreach($sub as $s) {
                                $dropdown[$s['id']] = $s[$item['rfield']];
                            }                                                                                  
                            print form_dropdown($index, $dropdown, $field[$index]);
                            $sub = $dropdown = array();
                            $res->free_result();
                        break;
                        
                        case 'checkbox':
                            print form_checkbox($index, 1, $field[$index] == 1 ? TRUE : FALSE);                            
                        break;
                        
                        case 'html':
                            $init['cols'] = 50;
                            $init['rows'] = 6;                            
                            print form_textarea($init);
                        break;
                        
                        case 'file':                            
                            print form_upload($init);                            
                        break;
                        
                        default:
                            print form_label('Тип не опознан', $index);
                    }
                print '</td></tr>';                
            }
        ?>                
    </table>
    <br />
    <input type="hidden" name="<?php print $table.'_'.$action.'_submit'; ?>" value="1">
    <input type="hidden" name="id" value="<?php print $field['id']; ?>">
    <input type="submit" name="<?php print $table.'_'.$action.'_submit'; ?>" value="Сохранить">
<?php print form_close(); ?>